In [1]:
import pandas as pd
import matplotlib.pyplot as plt
import descartes
import geopandas as gpd
from shapely.geometry import Point, Polygon
import plotly.express as px

%matplotlib inline
In [3]:
points = pd.read_csv("D:/KyotoProject/plot/testPoint.csv")
In [2]:
points_1809 = pd.read_csv("D:/KyotoProject/plot/export_plot.csv")
In [5]:
points.head()
Out[5]:
uid index aid uptime pos cd1 cd2 cd3 year month day hour minute second longitude latitude
0 ea82386f4623428f8a242b4e17f318ff 11571002 ARUKUMACHIKYOTO 41:50.0 (34.9766046,135.6965579) Android ja_JP 3.0.50 2018 9 1 0 41 49.963188 34.976605 135.696558
1 ea82386f4623428f8a242b4e17f318ff 11572775 ARUKUMACHIKYOTO 42:59.7 (34.9678067,135.6703647) Android ja_JP 3.0.50 2018 9 1 1 42 59.720997 34.967807 135.670365
2 ea82386f4623428f8a242b4e17f318ff 11577524 ARUKUMACHIKYOTO 45:05.3 (34.9678602,135.6704294) Android ja_JP 3.0.50 2018 9 1 4 45 5.261448 34.967860 135.670429
3 ea82386f4623428f8a242b4e17f318ff 11578406 ARUKUMACHIKYOTO 17:43.6 (34.9678602,135.6704294) Android ja_JP 3.0.50 2018 9 1 5 17 43.611878 34.967860 135.670429
4 ea82386f4623428f8a242b4e17f318ff 11580267 ARUKUMACHIKYOTO 18:25.9 (34.9678602,135.6704294) Android ja_JP 3.0.50 2018 9 1 6 18 25.923246 34.967860 135.670429
In [3]:
points_1809.head()
Out[3]:
uid index aid uptime pos cd1 cd2 cd3 year month day hour minute second longitude latitude
0 ea82386f4623428f8a242b4e17f318ff 11571002 ARUKUMACHIKYOTO 2018-09-01 00:41:49.963188 (34.9766046,135.6965579) Android ja_JP 3.0.50 2018 9 1 0 41 49.963188 34.976605 135.696558
1 ea82386f4623428f8a242b4e17f318ff 11572775 ARUKUMACHIKYOTO 2018-09-01 01:42:59.720997 (34.9678067,135.6703647) Android ja_JP 3.0.50 2018 9 1 1 42 59.720997 34.967807 135.670365
2 ea82386f4623428f8a242b4e17f318ff 11577524 ARUKUMACHIKYOTO 2018-09-01 04:45:05.261448 (34.9678602,135.6704294) Android ja_JP 3.0.50 2018 9 1 4 45 5.261448 34.967860 135.670429
3 ea82386f4623428f8a242b4e17f318ff 11578406 ARUKUMACHIKYOTO 2018-09-01 05:17:43.611878 (34.9678602,135.6704294) Android ja_JP 3.0.50 2018 9 1 5 17 43.611878 34.967860 135.670429
4 ea82386f4623428f8a242b4e17f318ff 11580267 ARUKUMACHIKYOTO 2018-09-01 06:18:25.923246 (34.9678602,135.6704294) Android ja_JP 3.0.50 2018 9 1 6 18 25.923246 34.967860 135.670429
In [4]:
#Insert unique index in the dataframe 
def insertIndex(df, index = 'uid'):
    """trasfer 'uid' in the data to integer unique ID, added into the 'idIndex' column.
   df = data frame file
   index = the columne name of the dataframe you want to use to generate the unique index, default value = 'uid'
    """
    nameList = list(df[index].unique())
    print("number of the unique index value: ",len(nameList))
    length = len(df)
    k = []
    for item in range(length):
        i = nameList.index(df['uid'][item])
        k.append(i)
    df['idIndex'] = k
    print(df.head())
    return df
In [5]:
plot_1809 = insertIndex(points_1809, index = 'uid')
number of the unique index value:  4358
                                uid     index              aid  \
0  ea82386f4623428f8a242b4e17f318ff  11571002  ARUKUMACHIKYOTO   
1  ea82386f4623428f8a242b4e17f318ff  11572775  ARUKUMACHIKYOTO   
2  ea82386f4623428f8a242b4e17f318ff  11577524  ARUKUMACHIKYOTO   
3  ea82386f4623428f8a242b4e17f318ff  11578406  ARUKUMACHIKYOTO   
4  ea82386f4623428f8a242b4e17f318ff  11580267  ARUKUMACHIKYOTO   

                       uptime                       pos      cd1    cd2  \
0  2018-09-01 00:41:49.963188  (34.9766046,135.6965579)  Android  ja_JP   
1  2018-09-01 01:42:59.720997  (34.9678067,135.6703647)  Android  ja_JP   
2  2018-09-01 04:45:05.261448  (34.9678602,135.6704294)  Android  ja_JP   
3  2018-09-01 05:17:43.611878  (34.9678602,135.6704294)  Android  ja_JP   
4  2018-09-01 06:18:25.923246  (34.9678602,135.6704294)  Android  ja_JP   

      cd3  year  month  day  hour  minute     second  longitude    latitude  \
0  3.0.50  2018      9    1     0      41  49.963188  34.976605  135.696558   
1  3.0.50  2018      9    1     1      42  59.720997  34.967807  135.670365   
2  3.0.50  2018      9    1     4      45   5.261448  34.967860  135.670429   
3  3.0.50  2018      9    1     5      17  43.611878  34.967860  135.670429   
4  3.0.50  2018      9    1     6      18  25.923246  34.967860  135.670429   

   idIndex  
0        0  
1        0  
2        0  
3        0  
4        0  
In [6]:
plot_1809.head()
Out[6]:
uid index aid uptime pos cd1 cd2 cd3 year month day hour minute second longitude latitude idIndex
0 ea82386f4623428f8a242b4e17f318ff 11571002 ARUKUMACHIKYOTO 2018-09-01 00:41:49.963188 (34.9766046,135.6965579) Android ja_JP 3.0.50 2018 9 1 0 41 49.963188 34.976605 135.696558 0
1 ea82386f4623428f8a242b4e17f318ff 11572775 ARUKUMACHIKYOTO 2018-09-01 01:42:59.720997 (34.9678067,135.6703647) Android ja_JP 3.0.50 2018 9 1 1 42 59.720997 34.967807 135.670365 0
2 ea82386f4623428f8a242b4e17f318ff 11577524 ARUKUMACHIKYOTO 2018-09-01 04:45:05.261448 (34.9678602,135.6704294) Android ja_JP 3.0.50 2018 9 1 4 45 5.261448 34.967860 135.670429 0
3 ea82386f4623428f8a242b4e17f318ff 11578406 ARUKUMACHIKYOTO 2018-09-01 05:17:43.611878 (34.9678602,135.6704294) Android ja_JP 3.0.50 2018 9 1 5 17 43.611878 34.967860 135.670429 0
4 ea82386f4623428f8a242b4e17f318ff 11580267 ARUKUMACHIKYOTO 2018-09-01 06:18:25.923246 (34.9678602,135.6704294) Android ja_JP 3.0.50 2018 9 1 6 18 25.923246 34.967860 135.670429 0
In [105]:
#points_test = points[50:200]
#points_test = points_1809[0:20000]
In [11]:
#select the data points with specific 'idIndex'
filterList = list(range(0,100)) # select the frist 50 idindex of points
points_test = plot_1809[plot_1809['idIndex'].isin(filterList)]
print(len(points_test),'points')
points_test.head()
68303 points
Out[11]:
uid index aid uptime pos cd1 cd2 cd3 year month day hour minute second longitude latitude idIndex
0 ea82386f4623428f8a242b4e17f318ff 11571002 ARUKUMACHIKYOTO 2018-09-01 00:41:49.963188 (34.9766046,135.6965579) Android ja_JP 3.0.50 2018 9 1 0 41 49.963188 34.976605 135.696558 0
1 ea82386f4623428f8a242b4e17f318ff 11572775 ARUKUMACHIKYOTO 2018-09-01 01:42:59.720997 (34.9678067,135.6703647) Android ja_JP 3.0.50 2018 9 1 1 42 59.720997 34.967807 135.670365 0
2 ea82386f4623428f8a242b4e17f318ff 11577524 ARUKUMACHIKYOTO 2018-09-01 04:45:05.261448 (34.9678602,135.6704294) Android ja_JP 3.0.50 2018 9 1 4 45 5.261448 34.967860 135.670429 0
3 ea82386f4623428f8a242b4e17f318ff 11578406 ARUKUMACHIKYOTO 2018-09-01 05:17:43.611878 (34.9678602,135.6704294) Android ja_JP 3.0.50 2018 9 1 5 17 43.611878 34.967860 135.670429 0
4 ea82386f4623428f8a242b4e17f318ff 11580267 ARUKUMACHIKYOTO 2018-09-01 06:18:25.923246 (34.9678602,135.6704294) Android ja_JP 3.0.50 2018 9 1 6 18 25.923246 34.967860 135.670429 0
In [12]:
token = "https://api.mapbox.com/tokens/v2/haomingyang?access_token=sk.eyJ1IjoiaGFvbWluZ3lhbmciLCJhIjoiY2szOGd6OWEwMDhxaTNjcnRxYXl2eXJ1ayJ9.IekZ9PZJeaVKaZqtHGTooQ" # you will need your own token
fig = px.scatter_mapbox(points_test, lat="longitude", lon="latitude", hover_name="idIndex", hover_data=["month", "day", "hour", "minute"],
                        color_discrete_sequence=["fuchsia"], zoom=6, height=800,  color="idIndex", size = "month", size_max = 6, color_continuous_scale=px.colors.cyclical.IceFire)
fig.update_layout(mapbox_style="open-street-map")
#fig.update_layout(mapbox_style="dark", mapbox_accesstoken=token)
fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})
fig.show()
In [14]:
token = "pk.eyJ1IjoiaGFvbWluZ3lhbmciLCJhIjoiY2szOGd2amIyMDllZzNjcWpqNnF6MjU0YyJ9.2dKHbwUYHrGe_V2bv0RXaQ" # you will need your own token
fig = px.scatter_mapbox(points_test, lat="longitude", lon="latitude", hover_name="idIndex", hover_data=["month", "day", "hour", "minute"],
                        color_discrete_sequence=["fuchsia"], zoom=6, height=1000,  color="idIndex", size = "hour", size_max = 5, color_continuous_scale=px.colors.cyclical.IceFire)
#fig.update_layout(mapbox_style="open-street-map")
fig.update_layout(mapbox_style="dark", mapbox_accesstoken=token)
fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})
fig.show()
In [64]:
#select the data points with specific 'idIndex'
filterList = list(range(0,1)) # select the frist 50 idindex of points
points_test = plot_1809[plot_1809['idIndex'].isin(filterList)]
print(len(points_test),'points')
points_test.head()
963 points
Out[64]:
uid index aid uptime pos cd1 cd2 cd3 year month day hour minute second longitude latitude idIndex
0 ea82386f4623428f8a242b4e17f318ff 11571002 ARUKUMACHIKYOTO 2018-09-01 00:41:49.963188 (34.9766046,135.6965579) Android ja_JP 3.0.50 2018 9 1 0 41 49.963188 34.976605 135.696558 0
1 ea82386f4623428f8a242b4e17f318ff 11572775 ARUKUMACHIKYOTO 2018-09-01 01:42:59.720997 (34.9678067,135.6703647) Android ja_JP 3.0.50 2018 9 1 1 42 59.720997 34.967807 135.670365 0
2 ea82386f4623428f8a242b4e17f318ff 11577524 ARUKUMACHIKYOTO 2018-09-01 04:45:05.261448 (34.9678602,135.6704294) Android ja_JP 3.0.50 2018 9 1 4 45 5.261448 34.967860 135.670429 0
3 ea82386f4623428f8a242b4e17f318ff 11578406 ARUKUMACHIKYOTO 2018-09-01 05:17:43.611878 (34.9678602,135.6704294) Android ja_JP 3.0.50 2018 9 1 5 17 43.611878 34.967860 135.670429 0
4 ea82386f4623428f8a242b4e17f318ff 11580267 ARUKUMACHIKYOTO 2018-09-01 06:18:25.923246 (34.9678602,135.6704294) Android ja_JP 3.0.50 2018 9 1 6 18 25.923246 34.967860 135.670429 0
In [40]:
token = "pk.eyJ1IjoiaGFvbWluZ3lhbmciLCJhIjoiY2szOGd2amIyMDllZzNjcWpqNnF6MjU0YyJ9.2dKHbwUYHrGe_V2bv0RXaQ" # you will need your own token
fig = px.scatter_mapbox(points_test, lat="longitude", lon="latitude", hover_name="idIndex", hover_data=["month", "day", "hour", "minute"],
                        color_discrete_sequence=["fuchsia"], zoom=6, height=1000,  color="idIndex", size = "hour", size_max = 10, 
                        color_continuous_scale=[[0, "rgb(166,206,227)"],
                        [0.25, "rgb(31,120,180)"],
                        [0.45, "rgb(178,223,138)"],
                        [0.65, "rgb(51,160,44)"],
                        [0.85, "rgb(251,154,153)"],
                        [1, "rgb(227,26,28)"]])
#fig.update_layout(mapbox_style="open-street-map")
fig.update_layout(mapbox_style="dark", mapbox_accesstoken=token)
fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})

fig.show()
In [100]:
#select the data points with specific 'idIndex'
filterList = list(range(3,10)) # select the frist 50 idindex of points
points_test = plot_1809[plot_1809['idIndex'].isin(filterList)]
print(len(points_test),'points')
points_test.head()
5170 points
Out[100]:
uid index aid uptime pos cd1 cd2 cd3 year month day hour minute second longitude latitude idIndex
2560 0fc28756b0a044bb99d9b8478136b158 11572767 ARUKUMACHIKYOTO 2018-09-01 01:42:50.086267 (35.0482286,135.7363208) Android ja_JP 3.0.50 2018 9 1 1 42 50.086267 35.048229 135.736321 3
2561 0fc28756b0a044bb99d9b8478136b158 11574513 ARUKUMACHIKYOTO 2018-09-01 02:45:45.306278 (35.0518042,135.7729558) Android ja_JP 3.0.50 2018 9 1 2 45 45.306278 35.051804 135.772956 3
2562 0fc28756b0a044bb99d9b8478136b158 11576406 ARUKUMACHIKYOTO 2018-09-01 03:58:44.062188 (35.0497341,135.7369319) Android ja_JP 3.0.50 2018 9 1 3 58 44.062188 35.049734 135.736932 3
2563 0fc28756b0a044bb99d9b8478136b158 11578820 ARUKUMACHIKYOTO 2018-09-01 05:33:05.692879 (35.0497787,135.7368329) Android ja_JP 3.0.50 2018 9 1 5 33 5.692879 35.049779 135.736833 3
2564 0fc28756b0a044bb99d9b8478136b158 11581062 ARUKUMACHIKYOTO 2018-09-01 06:43:01.882007 (35.04976,135.7370779) Android ja_JP 3.0.50 2018 9 1 6 43 1.882007 35.049760 135.737078 3
In [101]:
points_plot = points_test.query("day in [1,2,3,4,5]")
#points_plot = points_test
fig = px.line_mapbox(points_plot, lat="longitude", lon="latitude", color="idIndex", zoom=8, height=800)

fig.update_layout(mapbox_style="dark", mapbox_accesstoken=token)
fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})

fig.show()
In [149]:
len_item = len(dots['idIndex'].unique())
for i in range(len_item):
    temp = points_plot[points_plot.idIndex ==dots['idIndex'].unique()[i]]
    if i == 0:
        fig = go.Figure(go.Scattermapbox(
            mode = "markers+lines",
            lon = temp['latitude'],
            lat = temp['longitude'],
            marker = {'size': 10}))
    else:
        fig.add_trace(go.Scattermapbox(
            mode = "markers+lines",
            lon = temp['latitude'],
            lat = temp['longitude'],
            marker = {'size': 10}))

fig.update_layout(
    margin ={'l':0,'t':0,'b':0,'r':0},
    mapbox = {
        'center': {'lon': 135, 'lat': 35},
        #The built-in plotly.js styles objects are: open-street-map, white-bg, carto-positron, carto-darkmatter, 
        #stamen-terrain, stamen-toner, stamen-watercolor
        'style': "open-street-map",
        'center': {'lon': -20, 'lat': -20},
        'zoom': 1})

fig.show()